<?php

namespace App\Service\UserCenter;

use App\Constants\ErrorCode;
use App\Helpers\ImUtil;
use App\Model\User;
use App\Model\UserBlacklist;
use App\Service\BaseService;

/**
 * 黑名单移除
 */
class BlackRemoveService extends BaseService
{
    protected function RoVerifyList()
    {
        return [
            'black_user_id' => 'required|int',
        ];
    }

    public function handle()
    {
        $userId = $this->getUserId();
        $blackUserId = $this->request->input('black_user_id', 0);
        if ($blackUserId == $userId) return $this->setError(ErrorCode::PARAMETER_ERROR, '参数错误~');
        $result = UserBlacklist::removeRecord($userId, $blackUserId);
        //融云取消拉黑
        $users = User::getImAccounts([$userId, $blackUserId]);
        ImUtil::delBlackList($users[$userId], $users[$blackUserId]);
        return ['result' => 1];
    }
}
